﻿using System;
using System.Windows.Forms;
using static System.Windows.Forms.Control;

namespace SimpleConnection_UDP_WIN.utils
{
    internal class ViewUtil
    {

        /// <summary>
        /// 设置编辑框为空
        /// </summary>
        /// <param name="textBoxes"></param>
        public static void setEditBoxEmpty(params TextBox[] textBoxes)
        {
            foreach (TextBox box in textBoxes)
            {
                box.Text = "";
            }

        }



        /// <summary>
        /// 判断每一个 编辑框都不为空
        /// </summary>
        /// <param name="cc"></param>
        /// <returns></returns>
        public static bool IsFormTextBoxValid(ControlCollection cc)
        {
            bool isValid = true;

            // 遍历每个编辑框
            foreach (Control control in cc)
            {
                Console.WriteLine($"{control.Name}");

                if (control is TextBox textBox)
                {
                    Console.WriteLine($"{control.Name}:{textBox.Text}");
                    // 检查文本是否为空
                    if (string.IsNullOrEmpty(textBox.Text))
                    {
                        isValid = false;
                        // 显示错误消息
                        break;
                    }
                }
            }

            return isValid;
        }
    }
}
